unit Rails.Vcl.Grids;

interface

uses
  Rails.Vcl.ObjectGrid, System.UITypes, Vcl.CheckLst, System.Classes, Vcl.ExtCtrls, Vcl.Graphics,
  Vcl.Controls, Rails.Vcl.Components;

type
  TRailsGrid = class(TRailsObjectGrid)
  private
    aRow: Integer;
    aCol: Integer;
    fCheckListFilter: TCheckListBox;
    fCheckListHide: TCheckListBox;
    fSplitterList: TSplitter;

    fEditDialogFilter: TRailsEdit;
    fComboDialogFilter: TRailsEdit;
    fMathCaseDialogFilter: TRailsEdit;

    fFilter: Boolean;
  protected
    //Evento DropDown para arrastar a Coluna para os CheckListBox de Filtros
    procedure DragOverEvent(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
    procedure DragDropEvent(Sender: TObject; Source: TObject; X, Y: Integer);
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure NeedSearchPanel; override;
    procedure ControlSearchKeyUP(Sender: TObject; var Key: Word; Shift: TShiftState); override;
    procedure FilterRecords;
  end;

  procedure register;

implementation

uses
  Rails.Vcl.Utils, Rails.Utils, WinApi.Windows;

procedure register;
begin
  RegisterComponents('Rails', [TRailsGrid]);
end;

{ TRailsGrid }

procedure TRailsGrid.ControlSearchKeyUP(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then
    fPanelSearchText.Parent := nil;

  if (Key = VK_ESCAPE) and fFilter then

  else
    inherited;
end;

procedure TRailsGrid.DragDropEvent(Sender, Source: TObject; X, Y: Integer);
begin
  if (Source = Self) and ((Sender = fCheckListFilter) or (Sender = fCheckListHide)) then
  begin
    TCheckListBox(Sender).Items.Add(Cells[aCol,aRow]+'|'+GetColumnName(ACol));
    fEditTextToSearch.SetFocus;
    fFilter := True;
  end;
end;

procedure TRailsGrid.DragOverEvent(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  if Source = Self then
    Accept := True;
end;

procedure TRailsGrid.FilterRecords;
begin

end;

procedure TRailsGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited;
  if ssCtrl in Shift then
  begin
    MouseToCell(X,Y,aCol,aRow);
    if aRow = 0 then
      BeginDrag(True);
  end;
end;

procedure TRailsGrid.NeedSearchPanel;
begin
  inherited;
  fSplitterList := TSplitter.Create(fPanelFilter);
  fSplitterList.Parent := fPanelFilter;
  fSplitterList.Align := alLeft;
  fSplitterList.Width := 8;

  fCheckListFilter := TCheckListBox.Create(fPanelFilter);
  fCheckListFilter.Parent := fPanelFilter;
  fCheckListFilter.Align := alLeft;
  fCheckListFilter.Width := Round((fPanelFilter.Width-12)/2);
  fCheckListFilter.OnDragDrop := DragDropEvent;
  fCheckListFilter.OnDragOver := DragOverEvent;

  fCheckListHide := TCheckListBox.Create(fPanelFilter);
  fCheckListHide.Parent := fPanelFilter;
  fCheckListHide.Align := alClient;
  fCheckListHide.Width := Round((fPanelFilter.Width-12)/2);
  fCheckListHide.OnDragDrop := DragDropEvent;
  fCheckListHide.OnDragOver := DragOverEvent;
end;

end.
